#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>

int create_process(char* path, char* const args[], char* const env[], int wait)
{
    int ret = fork();
    
    if( ret == 0 ) {
        if( execve(path, args, env) == -1 ) {
            exit(-1);
        }
    }
    
    if( wait && ret ) {
        waitpid(ret, &ret, 0);
    }
    
    return ret;
}

int main(int argc, char* argv[])
{
    char* target = argv[1];
    char* const ps_argv[] = {target, NULL};
    char* const ps_envp[] = {"PATH=/bin:/usr/bin", "TEST=Delphi", NULL};
    
    int result = 0;
    
    if( argc < 2 )
        exit(-1);
    
    printf("current: %d\n", getpid());
    
    result = create_process(target, ps_argv, ps_envp, 0);
    
    printf("result = %d\n", result);
    
    return 0;
}
